﻿'
' Will Strohl (wills@strohlsitedesign.com)
' http://www.willstrohl.com
'
'Copyright (c) 2010, Will Strohl
'All rights reserved.
'
'Redistribution and use in source and binary forms, with or without modification, are 
'permitted provided that the following conditions are met:
'
'Redistributions of source code must retain the above copyright notice, this list of 
'conditions and the following disclaimer.
'
'Redistributions in binary form must reproduce the above copyright notice, this list 
'of conditions and the following disclaimer in the documentation and/or other 
'materials provided with the distribution.
'
'Neither the name of StrohlSiteDesign.com nor the names of its contributors may be 
'used to endorse or promote products derived from this software without specific prior 
'written permission.
'
'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
'EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
'OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
'SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
'INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
'TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
'BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
'CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
'ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 
'DAMAGE.
'

Imports DotNetNuke.Services.Exceptions

Namespace WillStrohl.Modules.QueryToGrid

    Partial Public MustInherit Class Options
        Inherits WNSPortalModuleBase

#Region " Event Handlers "

        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Try

                If Not Me.Page.IsPostBack Then
                    Me.BindData()
                End If

            Catch exc As Exception ' Module failed to load
                ProcessModuleLoadException(Me, exc, Me.IsEditable)
            End Try

        End Sub

        Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
            Me.SendTo(NavigateURL)
        End Sub

        Private Sub cmdSaveOptions_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSaveOptions.Click

            If Me.Page.IsValid Then
                Me.SaveOptions()
                Me.SendTo(NavigateURL)
            End If

        End Sub

#End Region

#Region " Helper Methods "

        Private Sub BindData()

            Me.LocalizeModule()

            If Not Me.GridSettings Is Nothing Then
                Me.txtRecordsPerPage.Text = Me.GridSettings.RecordsPerPage.ToString
            Else
                Me.txtRecordsPerPage.Text = QueryToGridController.RECORDSPERPAGE_DEFAULT.ToString
            End If

        End Sub

        Private Sub LocalizeModule()

            Me.lblRecordsPerPage.Text = Me.GetLocalizedString("lblRecordsPerPage.Text")
            Me.lblRecordsPerPage.HelpText = Me.GetLocalizedString("lblRecordsPerPage.Help")
            Me.cmdSaveOptions.Text = Me.GetLocalizedString("cmdSaveOptions.Text")
            Me.cmdCancel.Text = Me.GetLocalizedString("cmdCancel.Text")

        End Sub

        Private Sub SaveOptions()

            Dim ctlModule As New QueryToGridController

            If Not Me.GridSettings Is Nothing Then
                ctlModule.UpdateSettings(Me.ModuleId, Integer.Parse(Me.txtRecordsPerPage.Text, Globalization.NumberStyles.Integer))
            Else
                ctlModule.AddSettings(Me.ModuleId, Integer.Parse(Me.txtRecordsPerPage.Text, Globalization.NumberStyles.Integer))
            End If

        End Sub

#End Region

    End Class

End Namespace